//
//  WBWelcomeViewController.swift
//  WeiBo
//
//  Created by 韩菲菲 on 16/8/11.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

import UIKit
import SDWebImage

class WBWelcomeViewController: UIViewController {

    override func viewDidLoad() {
       super.viewDidLoad()
        
       setupUI()
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        //更新约束
        headImageView.snp_updateConstraints(closure: { (make) in
            
            make.top.equalTo(view).offset(100)
            
                 })
        
        //制作动画
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            
            self.view.layoutIfNeeded()
            
            }) { (_) in
                //动画结束 显示label
                UIView.animateWithDuration(0.5, animations: {
                    
                    self.messageLabel.alpha = 1
                    
                    }, completion: { (_) in
                        
                        //跳转控制器 通过通知跳转
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwithViewController, object: nil)
                })
                
        }
    }
    
    
    
    //设置界面
    func setupUI() {
        
        //添加控件
        view.addSubview(backGroundImageView)
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        
        
        //设置背景图片的约束
        backGroundImageView.snp_makeConstraints { (make) in
            
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
            
        }
        //设置头像图片的约束
        headImageView.snp_makeConstraints { (make) in
            //大小是90 * 90 top 距离 400 ， 中心
            make.size.equalTo(CGSizeMake(90, 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
            
        }
        //设置文字的约束
        messageLabel.snp_makeConstraints { (make) in
            
            //居中
            make.centerX.equalTo(view)
            //距离头像图片的底部16
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            
        }
        
    }
    
    
    //懒加载Label
    private lazy var messageLabel: UILabel = {
        //创建Label
        let label = UILabel()
        //字体18
        label.font = UIFont.systemFontOfSize(18)
        //字体颜色
        label.textColor = UIColor.darkGrayColor()
        //透明度
        label.alpha = 0
        //内容居中
        label.textAlignment = .Center
        //文字
        label.text = "欢迎回来"
      
        return label
    
    }()
    
    //懒加载头像图片
    private lazy var headImageView : UIImageView = {
    
        let imageView = UIImageView(imgName: "avatar_default_big")

       imageView.wb_setImageWithString(WBUserAccountViewModel.sharedUserAccountViewModel.userAccount?.avatar_large, placeholderImageName: "avatar_default_big")
        
        //裁剪图片
        imageView.layer.cornerRadius = 45
        imageView.layer.masksToBounds = true
        return imageView
    
    }()
    
    //懒加载背景图片
    private lazy var backGroundImageView: UIImageView = {
    
        let imageView = UIImageView(imgName: "ad_background")
        
        return imageView
    
    }()

    

}
